package com.util.servlet;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class MyServlet extends HttpServlet {
    private String message;

    @Override
    public void init() throws ServletException {
        //执行密码的初始化
        message = "我是孙猴子";

    }

//
//@Override
//    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        //设置响应内容类型
//        resp.setContentType("text/html");
//        //设置响应编码 否则为乱码
//        resp.setCharacterEncoding("utf-8");
//        //实际逻辑
//        PrintWriter out = resp.getWriter();
//        out.println(String.format("<h1>%s</h1>",message));
//        System.out.println("有访问者");
//        System.out.println(req.getParameter("account"));
//        System.out.println(req.getParameter("password"));
//        System.out.println("啥也没有");
//        System.out.println("我是王");
//        System.out.println("q j ");
//        System.out.println("ab");
//        System.out.println("cc");
//        System.out.println("dd");
//        System.out.println("ee");
//    }
    @Override
    public void destroy() {
        super.destroy();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置响应内容类型
        resp.setContentType("text/html");
        //设置响应编码 否则为乱码
        resp.setCharacterEncoding("utf-8");
        //实际逻辑
        PrintWriter out = resp.getWriter();
        out.println(String.format("<h1>%s</h1>",message));
        System.out.println("有访问者");
        System.out.println(req.getParameter("account"));
        System.out.println(req.getParameter("password"));
        resp.setStatus(110);

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
